﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Framework.Extensions
{
    public static class EnumerableExtensions
    {
        public static void AddRange<T>(this IList<T> source, params T[] args)
        {
            args.Foreach(source.Add);
        }
        public static void Foreach<T>(this IEnumerable<T> source, Action<T> action)
        {
            if (action == null) throw new ArgumentNullException("action");
            foreach (var item in source)
            {
                action(item);
            }
        }
        public static IEnumerable<T> Reify<T>(this IEnumerable<T> source)
        {
            var list = source as IList<T>;
            if (list != null) return list;
            var arr = source as T[];
            if (arr != null) return arr;
            return source.ToList();
        }
        public static string CreateString(this IEnumerable<string> source)
        {
            return CreateString(source, string.Empty);
        }
        public static string CreateString(this IEnumerable<string> source, string splitter)
        {
            return string.Join(splitter, source.ToArray());
        }
        public static bool IsNullOrEmpty<T>(this List<T> source)
        {
            return source == null || 0 == source.Count;
        }
    }
}
